package com.tac.controller.common;

import com.tac.common.result.Result;
import com.tac.common.utils.ImgUtils;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Api(tags = "通用接口")
@CrossOrigin
@RestController
@RequestMapping("/common")
public class CommonController {

    @Value("${img.path}")
    private String baseUrl;

    @PostMapping("/uploadImg")
    public Result uploadImg(MultipartFile file) throws IOException {
        String imgName = ImgUtils.getImgName(baseUrl, file);
        return Result.success(imgName);
    }
}
